package top.songxs.yygh.hosp.cmn.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.songxs.yygh.common.result.R;
import top.songxs.yygh.model.cmn.Dict;
import top.songxs.yygh.hosp.cmn.service.DictService;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Api(tags = "Dict数据字典接口")
@RequestMapping("/admin/cmn/dict")
public class DictController {
    @Autowired
    private DictService dictService;

    @GetMapping("findByDictCode/{dictCode}")
    public R findByDictCode(@PathVariable String dictCode) {
        List<Dict> list = dictService.findByDictCode(dictCode);
        return R.ok().data("list", list);
    }

    //根据value查询省市区名称
    @ApiOperation(value = "根据value查询省市区名称")
    @GetMapping("getName/{value}")
    public String getName(@PathVariable String value) {
        return dictService.getName(value, "");

    }

    //根据医院查询医院等级名称
    @ApiOperation(value = "根据医院查询医院等级名称")
    @GetMapping("getName/{value}/{dictCode}")
    public String getHospitalName(@PathVariable String value, @PathVariable String dictCode) {
        return dictService.getName(value, dictCode);

    }

    //根据parent_id查询所有
    @GetMapping("/findChildData/{id}")
    @ApiOperation(value = "根据数据id查询子数据列表")
    public R findAll(@PathVariable("id") Long id) {
        List<Dict> dictList = dictService.findChildData(id);
        return R.ok().data("list", dictList);
    }

    @ApiOperation(value = "文件导入上传")
    @PostMapping("importData")
    public R importData(MultipartFile file) {

        dictService.importData(file);
        return R.ok();
    }

    @ApiOperation(value = "文件导出下载")
    @GetMapping("exportData")
    public void exportData(HttpServletResponse response) {
        dictService.exportData(response);

    }


}
